import { getCategoryList, getBannerList, getFloorList } from "../../api"
/* 数据源 */
const state = {
    categoryList: [],
    bannerList: [],
    floorList: []
}
/* 间接操作数据 发送ajax请求 */
const actions = {
    async reqCategoryList({ commit }) {
        const result = await getCategoryList();
        if (result.code === 200) {
            commit("RECEVIE_CATEGORYLIST", result.data)
        }
    },
    /* 发送ajax 获取bannerlist */
    async reqBannerList(context) {
        const result = await getBannerList();
        // console.log("actions调用了", result);
        if (result.code === 200) {
            //拿到数据后 通过commit调用mutations中的方法 将数据存到vuex中
            context.commit("RECEVIE_BANNERLIST", result.data)
        }
    },
    async reqFloorList(context) {
        const result = await getFloorList();
        /* console.log(result); */
        if (result.code === 200) {
            context.commit("RECEVIE_FLOORLIST", result.data)
        }
    },

}


/* 直接操作数据源，不写任何逻辑代码 */
const mutations = {
    /* 收到的数据存到vuex中 */
    RECEVIE_CATEGORYLIST(state, categoryList) {
        state.categoryList = categoryList;
    },
    RECEVIE_BANNERLIST(state, value) {
        // console.log("mutations调用了", state, value, "+++");
        state.bannerList = value;
    },
    RECEVIE_FLOORLIST(state, value) {
        state.floorList = value
    }

}
const getters = {}

export default {
    state,
    actions,
    mutations,
    getters
}